
<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <script src="https://cdn.bootcss.com/jquery/2.2.4/jquery.min.js"></script>
    <title>添加商品</title>
</head>
<body>
<form id="uploadForm" enctype="multipart/form-data">
    产品名字：<input type="text" name="name" placeholder="请输入产品名字" value=""/><br>
    产品价格：<input type="number" name="price" placeholder="请输入产品价格" value=""/><br>
    产品描述：<input type="text" name="description" placeholder="请输入产品描述" value=""/><br>
    产品图片:<input type="file" name="img" multiple="multiple"/><br>
    产品类型：<input list="productType" id="productTypeList" type="text" name="ptype"/>
    <datalist id="productType">
        <option value="CPU">CPU</option>
        <option value="GPU">显卡</option>
        <option value="RAM">内存</option>
    </datalist>
</form>
<button id="upload">上传文件</button>
</body>
<script type="text/javascript">
    $(function () {
        $("#upload").click(function () {
            var formData = new FormData($('#uploadForm')[0]);
            $.ajax({
                type: 'post',
                url: "http://localhost:8080/untitled/addProduct",
                data: formData,
                cache: false,
                processData: false,
                contentType: false,
            }).success(function (data) {
                alert("上传成功");
            }).error(function () {
                alert("上传失败");
            });
        });
    });
</script>
</html>
 
